import 'dart:ui';
import 'package:flutter/material.dart';

void main() => runApp(_widgetForRoute(window.defaultRouteName));

Widget _widgetForRoute(String route) {
  return MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      appBar: AppBar(
        title: Text('MyFlutter页面'),
        centerTitle: true,
      ),
      body: _getWidget(route),
    ),
  );
}

Widget _getWidget(String route) {
  switch (route) {
    case '/':
      return _buildDefaultWidget();
    case '/my_route':
      return _buildMyRouteWidget();
    default:
      return _buildOtherWidget(route);
  }
}

Widget _buildDefaultWidget() {
  return Center(
    child: Text('default route'),
  );
}

Widget _buildMyRouteWidget() {
  return Center(
    child: Column(
      children: <Widget>[
        //Text('Flutter页面，route=$route, params=$paramsJson'),
        Text('Flutter页面，route=MyRoute'),
        RaisedButton(
          textColor: Colors.blue,
          child: Text("跳转原生页面"),
          onPressed: () {
            print("跳转原生页面");
            // 跳转原生页面
            // Map<String, dynamic> result = {'name': '你好，${params["name"]}'};
            // nativeChannel.invokeMethod('jumpToNative', result);
          },
        ),
      ],
    ),
  );
}

Widget _buildOtherWidget(String routeName) {
  return Center(
    child: Text('Unknown route: $routeName'),
  );
}
